import CRFPP
global tagger
tagger = None
def crf_seg_init(model_path):
    global tagger
    tagger = CRFPP.Tagger('-m ' + model_path + ' -v 3 -n2')

def crf_seg(sentence):
    tagger.clear()
    data = ''
    for char in sentence:
        tagger.add(char + ' B\n')

    tagger.parse()
    for i in range(tagger.size()):
        if (tagger.y2(i)) == 'B':
            data += ' '

        data += sentence[i]
    return data.strip()
if __name__ == '__main__':
    sentence = '在自然语言处理中，分词作为各类不同任务的前置任务显得非常重要。这个网站是对几种主流算法的总结，并给出其测试实例。'
    print(crf_seg(sentence))